/*
 *  Copyright (C) 2010 MADSA.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *
 *  Author:  Jorge Pintado de Santiago
 *          
 */

package com.madsa.maps;

import com.google.android.maps.MapView;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class MyMapView extends MapView{
	
	private long lastTouchTime = -1;
    
	public MyMapView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}
	public MyMapView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	public MyMapView(Context context, String apiKey) {
		super(context, apiKey);
	}

	public boolean onInterceptTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			long thisTime = System.currentTimeMillis();
			if (thisTime - lastTouchTime < 250) {
				//Double tap
				this.getController().zoomInFixing((int) event.getX(), (int) event.getY());
				lastTouchTime = -1;
			} else {
				//Too slow
				lastTouchTime = thisTime;
			}
		}
		return super.onInterceptTouchEvent(event);
	}
	
	int px,py;
	int i=0;
	String dispatch = "false";
	

	
	@Override 
    protected void dispatchDraw(Canvas canvas){
	     canvas.save();
		px=canvas.getClipBounds().centerX();
		py=canvas.getClipBounds().centerY();
			canvas.rotate(-bearing,px,py);
			
			onDraw(canvas);
			i++;
	    	dispatch="true";
    	super.dispatchDraw(canvas);
		     canvas.restore();
	}
	public int get_px() {
		return px;
	}
	public int get_py() {
		return py;
	}
	public String get_dispatch() {
		return dispatch;
	}

	private float bearing;
	private float pitch = 0;
	private float roll = 0;

	public void setBearing(float _bearing) {
		bearing = _bearing;
	}
		
	public float getBearing() {
		return bearing;
	}
	
	public float getPitch() {
		return pitch;
	}
	
	public void setPitch(float pitch) {
		this.pitch = pitch;
	}
	
	public float getRoll() {
		return roll;
	}
	
	public void setRoll(float roll) {
		this.roll = roll;
	}

    
}